/*
	维护某种鱼的状态
*/
package maintainer

import (
	"fish-scaner/binary"
	"fmt"
	"sync"

	"github.com/gogf/gf/encoding/gjson"
)

type fishsMaintainer struct {
	collectMu							sync.Mutex
	Collecting							bool
	zipMu								sync.Mutex
	Ziping								bool
	downloadMu							sync.Mutex
	Downloading							bool
	Err									error
	PyStdout							string
	fishdb, systematics, willZipDirName string
}

func init() {
	// fmt.Println(new(fishsMaintainer).L.RLocker)
	// j, _ := gjson.LoadContent(binary.Binary[`test.json`])
	// fmt.Println(j.GetJsonMa())
	j, _ := gjson.LoadJson(binary.Binary[`test.json`])
	jsonTest := j.GetMap("map")
	for key, val := range jsonTest {
		fmt.Println(key, `: `, val)
	}
}

func (this *fishsMaintainer) Lock(key string) {
	switch key {
	case `collect`:
		this.collectMu.Lock()
		this.Collecting = true
	case `zip`:
		//打包时不许爬取和下载
		this.downloadMu.Lock()
		this.Downloading = true
		this.collectMu.Lock()
		this.Collecting = true
		this.zipMu.Lock()
		this.Ziping = true
	case `download`:
		//下载时不许打包,但不妨碍爬取
		this.zipMu.Lock()
		this.Ziping = true
		this.downloadMu.Lock()
		this.Downloading = true
	}
}

func (this *fishsMaintainer) unLock(key string) {
	switch key {
	case `collect`:
		this.Collecting = false
		this.collectMu.Unlock()
	case `zip`:
		//打包时不许爬取和下载
		this.Downloading = false
		this.downloadMu.Unlock()
		this.Collecting = false
		this.collectMu.Unlock()
		this.Ziping = false
		this.zipMu.Unlock()
	case `download`:
		//下载时不许打包,但不妨碍爬取
		this.Ziping = false
		this.zipMu.Unlock()
		this.Downloading = false
		this.downloadMu.Unlock()
	}
}
